home *** CD-ROM | disk | FTP | other *** search
/ Aminet 16 / Aminet 16 (1996)(GTI - Schatztruhe)[!][Dec 1996].iso / Aminet / dev / src / wangisrc.lha / wangi / z / AGPrefs / AmigaGuide.PAS < prev    next >
Pascal/Delphi Source File  |  1995-07-16  |  36KB  |  1,339 lines

  1. USES 
  2.     Intuition, Exec, GadTools, Graphics, Utility, 
  3.     Amiga, Asl, AmigaDos, Icon, Workbench, DOS;
  4.  
  5. {$F-,I-,R-,S-,V-,M 5,1,1,15}
  6.  
  7.  
  8. Type
  9.     pPreset = ^tPreset;
  10.     tPreset = Array[1..9] of byte;
  11.     
  12. CONST    
  13.     MAX_COLOURS = 207; { max. used by AmigaGuide }
  14.     
  15.     Version : String[40] = '$VER: AmigaGuide_Prefs 36.144 (03.12.94)'#0;
  16.  
  17.     { gadget identifiers                   }
  18.     G_NI    = 0;  { Null init. gadget      }
  19.     G_PATH  = 1;  { Path listview gadget   }
  20.     G_PATHT = 2;  { Path string gadget     }
  21.     G_FR    = 3;  { File requester gadget  }
  22.     G_TEXT  = 4;  { Text cycle gadget      }
  23.     G_PENS  = 5;  { Pen listview gadget    }
  24.     G_PENP  = 6;  { Pen palette gadget     }
  25.     G_NEW   = 7;  { New path gadget        }
  26.     G_REM   = 8;  { Path reove gadget      }
  27.     G_SAVE  = 9;  { Save gadget            }
  28.     G_USE   = 10; { Use gadget             }
  29.     G_CAN   = 11; { Cancel gadget          }
  30.     G_CC    = 12; { CreateContext() gadget }
  31.  
  32.     { identifiers used to refer to the pen array }
  33.     P_BG   = 0; { Background                     }
  34.     P_BT   = 1; { button text                    }
  35.     P_BBG  = 2; { button background              }
  36.     P_HBT  = 3; { highlighted button text        }
  37.     P_HBBG = 4; { highlighted button background  }
  38.     P_OP   = 5; { outline pen                    }
  39.     P_HOP  = 6; { highlighted outline pen        }
  40.     P_TBGP = 7; { Text on background pen         }
  41.     
  42.     { identifiers for text gadget           }
  43.     T_BUTTON    = 0; { button link point    }
  44.     T_HIGHLIGHT = 1; { highlight link point }
  45.     T_UNDERLINE = 2; { underline link point }
  46.     T_BOLD      = 3; { bold link point      }
  47.     T_ITALIC    = 4; { italic link point    }
  48.     T_NULL      = 5;
  49.     
  50.     { identifiers for the menu items          }
  51.  
  52.     M_OPEN  = 0; { Open... item               }
  53.     M_SAVAS = 1; { Save As... item            }
  54.     M_ABOUT = 2; { About item                 }
  55.     M_QUIT  = 3; { quit item                  }
  56.  
  57.     M_DEF   = 4; { restore to defaults item   }
  58.     M_LASTS = 5; { restore to last saved item }
  59.     M_REST  = 6; { restore item               }
  60.     M_PRE   = 8; { presets submenu            }
  61.     M_PRE1  = 9;
  62.     M_PRE2  = 10;
  63.     M_PRE3  = 11;
  64.     M_PRE4  = 12;
  65.     M_PRE5  = 13;
  66.     M_PRE6  = 14;
  67.     M_PRE7  = 15;
  68.     M_PRE8  = 16;
  69.     M_PRE9  = 17;
  70.     M_PREA  = 18;
  71.     M_PREB  = 19;
  72.     M_PREM  = 20;
  73.     M_PREMAX= 20;
  74.     
  75.     M_ICON  = 20; { Create Icons? item         }
  76.     
  77.     Presets : Array[1..12] of tPreset = 
  78.         ((2,1,2,1,3,0,0,1,T_BOLD  ), { Sharp            }
  79.          (0,2,3,1,7,0,0,1,T_BUTTON), { Wangi            }
  80.          (1,2,1,5,1,0,0,2,T_ITALIC), { Strappado        }
  81.          (5,6,3,7,2,0,0,1,T_BUTTON), { Skerza           }
  82.          (0,1,0,1,3,0,0,1,T_BUTTON), { Default          }
  83.          (0,1,0,0,1,0,0,1,T_BUTTON), { Monochrome       }
  84.          (0,2,0,2,3,0,0,2,T_BUTTON), { Light & Easy     }
  85.          (7,1,7,1,4,0,0,1,T_BUTTON), { Baked Beans      }
  86.          (7,2,3,5,2,0,0,1,T_BUTTON), { Sadad            }
  87.          (3,1,5,2,4,0,0,2,T_BUTTON), { heterophyte      }
  88.          (5,1,5,4,7,0,0,1,T_ITALIC), { Alcohol Results  }
  89.          (4,1,5,7,3,0,0,1,T_BUTTON));{ MagicWB          }
  90.     
  91.     curpathord : Integer = -1;
  92.     curpen : Integer = 0;
  93.     
  94. TYPE 
  95.     tPens = Array[P_BG..P_TBGP] of Integer;
  96.     tGD = Record
  97.         gd_Path : pList;
  98.         gd_Text : T_BUTTON..T_ITALIC;
  99.         gd_Pens : tPens;
  100.     end;
  101.     tProgVars = Record
  102.         arg_Edit,
  103.         arg_Use,
  104.         arg_Save,
  105.         arg_SIcons    : Boolean;
  106.         arg_From,
  107.         arg_PubScreen : String;
  108.     End;
  109.     
  110. VAR
  111.     RememberKey : pRemember;
  112.     gads        : Array[G_NI..G_CC] of pGadget;
  113.     vi          : Pointer;
  114.     TheWindow   : pWindow;
  115.     menustrip   : pMenu;
  116.     OK          : Boolean;
  117.     TextLabs    : Array[T_BUTTON..T_NULL] of STRPTR;
  118.     PenLabs     : Array[P_BG..P_TBGP] of STRPTR;
  119.     PenList     : pList;
  120.     n           : P_BG..P_TBGP;
  121.     Topaz8      : tTextAttr;
  122.     GD          : tGD;
  123.     t           : Array[0..22] of LONG;
  124.     ZoomS       : Array[0..3] of Integer;
  125.     v           : tProgVars;
  126.     TBS         : LONG;
  127.     HighLightPen: Integer;
  128.     
  129.  
  130.  
  131. function CStrConstPtrAR(rk : ppRemember; s : String) : STRPTR;
  132.  
  133. VAR
  134.     p : STRPTR;
  135.     
  136. begin
  137.   s := s + #0;                                   { Make "C" string               }
  138.   p := AllocRemember(rk, length(s), MEMF_CLEAR); { Get some mem for it           }
  139.   move(s[1], p^, length(s));                     { Move s into newly alloc'd mem }
  140.   CStrConstPtrAR := p;                           { Return the pointer            }
  141. end;
  142.  
  143. {$I ToolType.Pas }
  144.  
  145. Function UpperStr(s : String) : String;
  146. Var
  147.     X : Byte;
  148. Begin
  149.   For X := 1 To Length(S) Do
  150.     S[X] := UpCase(S[X]);
  151.   UpperStr := S;
  152. End;
  153.  
  154. Function GetDir(dir : String; Drawer, Save : Boolean) : String;
  155.     
  156. VAR
  157.     fr : pFileRequester;
  158.     buf : String;
  159.     dirpart, filepart, ext : String;
  160.  
  161. Begin
  162.     GetDir := '';
  163.     t[0] := ASLFR_TitleText;
  164.     If drawer then
  165.         t[1] := LONG(CStrConstPtrAR(@RememberKey, 'Select a directory'))
  166.     else
  167.         t[1] := LONG(CStrConstPtrAR(@RememberKey, 'Select a file'));
  168.     t[2] := ASLFR_DrawersOnly;
  169.     If drawer then
  170.         t[3] := True_
  171.     else
  172.         t[3] := False_;
  173.     t[4] := ASLFR_InitialDrawer;
  174.     If Drawer then begin
  175.         t[5] := LONG(CStrConstPtrAR(@RememberKey, dir));
  176.         t[6] := TAG_IGNORE;
  177.     End else begin
  178.         FSplit(dir, dirpart, filepart, ext);
  179.         dirpart := dirpart + #0;
  180.         filepart := filepart + ext + #0;
  181.         t[5] := LONG(@dirpart[1]);
  182.         t[6] := ASLFR_InitialFile;
  183.         t[7] := LONG(@filepart[1]);
  184.     End;
  185.     t[8] := ASLFR_Window;
  186.     t[9] := long(TheWindow);
  187.     t[10] := ASLFR_Flags1;
  188.     if save then
  189.         t[11] := FRF_DOSAVEMODE
  190.     else
  191.         t[11] := 0;
  192.     t[12] := TAG_DONE;
  193.     fr := AllocASLRequest(ASL_FileRequest, @t);
  194.     if fr <> NIL then begin
  195.         if AslRequest(fr, NIL) then begin
  196.             buf := PtrToPas(STRPTR(fr^.fr_Drawer));
  197.             buf := buf + #0;
  198.             if NOT drawer then begin
  199.                 OK := AddPart(@buf[1], STRPTR(fr^.fr_File), 255);
  200.             End;
  201.             GetDir := PtrToPas(@buf[1]); 
  202.         end;
  203.         FreeAslRequest(fr);
  204.     End;
  205. End;
  206.  
  207. Procedure SetDefault;
  208.  
  209. begin
  210.     { Clear path                      }
  211.     NewList(GD.gd_Path);
  212.     { default for pens is:            }
  213.     { SetEnv AmigaGuide/Pens 01013001 }
  214.     GD.gd_Pens[P_BG]   := 0;
  215.     GD.gd_Pens[P_BT]   := 1;
  216.     GD.gd_Pens[P_BBG]  := 0;
  217.     GD.gd_Pens[P_HBT]  := 1;
  218.     GD.gd_Pens[P_HBBG] := 3;
  219.     GD.gd_Pens[P_OP]   := 0;
  220.     GD.gd_Pens[P_HOP]  := 0;
  221.     GD.gd_Pens[P_TBGP] := 1;
  222.     { default for text is:            }
  223.     { SetEnv AmigaGuide/Text BUTTON   }
  224.     GD.gd_Text := T_BUTTON;
  225. end;
  226.  
  227. Procedure SetPrefs(destination : String; ToFile : Boolean);
  228.  
  229. TYPE
  230.     pBuf = ^tBuf;
  231.     tBuf = packed Array[0..1000] of char;
  232.     
  233. VAR
  234.     flags       : LONG;
  235.     len         : Integer;
  236.     ch          : char;
  237.     s,s2        : String;
  238.     inq         : Boolean;
  239.     node        : pNode;
  240.     pathvarname,
  241.     textvarname,
  242.     penvarname,
  243.     drwname,
  244.     pathptr,
  245.     textptr,
  246.     penptr,
  247.     olddt       : STRPTR;
  248.     tt          : Array[0..1] of STRPTR;
  249.     oldtt       : ppByte;
  250.     l,f         : BPTR;
  251.     offset      : 0..1002;
  252.     err         : LONG;
  253.     dobj : pDiskObject;
  254.     
  255.     
  256. Function MakePath : STRPTR;
  257.  
  258. Var
  259.     b : pBuf;
  260.     
  261. Begin
  262.     b := AllocVec(Sizeof(tBuf), MEMF_CLEAR);
  263.     if b <> NIL then begin
  264.         offset := 0;
  265.         node := GD.gd_Path^.lh_Head;
  266.         While (node^.ln_Succ <> NIL) and (offset < 1000) do begin
  267.             S := '"'+PtrToPas(node^.ln_Name)+'" ';
  268.             if S <> '"" ' then begin
  269.                 move(s[1], b^[offset], Length(s));
  270.                 offset := offset + Length(s);
  271.             end;            
  272.             node := node^.ln_Succ;
  273.         end;
  274.         if ToFile then begin
  275.             b^[offset-1] := ''#10;
  276.             inc(offset);
  277.         End;
  278.         b^[offset-1] := ''#0;
  279.     End;
  280.     MakePath := STRPTR(b);
  281. End;
  282.  
  283. Procedure FreePath(t : STRPTR);
  284.  
  285. Begin
  286.     FreeVec(t);
  287. End;
  288.  
  289. Function MakeText : STRPTR;
  290.  
  291. Begin
  292.     Case GD.gd_Text of
  293.         T_BUTTON : s := 'BUTTON';
  294.         T_HIGHLIGHT : s := 'HIGHLIGHT';
  295.         T_UNDERLINE : s := 'UNDERLINE';
  296.         T_BOLD : s := 'BOLD';
  297.         T_ITALIC : s := 'ITALIC';
  298.     end;
  299.     if ToFile then
  300.         s := s + #10;
  301.     s := s + #0; 
  302.     MakeText := STRPTR(@s[1]);
  303. End;
  304.  
  305. Function MakePens : STRPTR;
  306.  
  307. Var
  308.     n : Integer;
  309.  
  310. begin
  311.     With GD do begin
  312.         s2 := '';
  313.         for n := P_BG to P_TBGP do
  314.             s2 := s2 + chr(gd_Pens[n]+48);
  315.         if ToFile then
  316.             s2 := s2 + #10;
  317.         S2 := s2 + #0;
  318.     End;
  319.     MakePens := STRPTR(@s2[1]);
  320. end;
  321.     
  322. begin
  323.     pathptr := MakePath;
  324.     textptr := MakeText;
  325.     penptr  := MakePens;
  326.     drwname := CStrConstPtrAR(@RememberKey, destination);
  327.  
  328.     If ToFile then begin
  329.         f := Open(drwname, MODE_NEWFILE);
  330.         if f <> NULL then begin
  331.             err := FPuts(f,pathptr);
  332.             err := FPuts(f,textptr);
  333.             err := FPuts(f,penptr);
  334.             OK := Close_(f);
  335.             Ok := SetProtection(drwname, FIBF_EXECUTE);
  336.             Ok := SetComment(drwname, CStrConstPtrAR(@RememberKey, 
  337.               'Preferences for Amigaguide. Written by Amigaguide Prefs, ©Lee Kindness'));
  338.             If v.arg_SIcons then begin
  339.                 { if DDTI has been installed to default location then use default prefs icon }
  340.                 dobj := GetDiskObject(CStrConstPtrAR(@RememberKey, 'DEVS:Icons/def_pref'));
  341.                 if dobj = NIL then
  342.                     dobj := GetDefDiskObject(WBPROJECT);
  343.                 if dobj <> NIL then begin
  344.                     olddt := dobj^.do_DefaultTool;
  345.                     oldtt := dobj^.do_ToolTypes;
  346.                     dobj^.do_DefaultTool := CStrConstPtrAR(@RememberKey, FExpand(ParamStr(0)));
  347.                     s := 'ACTION=USE'#0;
  348.                     tt[0] := @s[1];
  349.                     tt[1] := NIL;
  350.                     dobj^.do_ToolTypes := @tt;
  351.                     Ok := PutDiskObject(drwname,dobj);
  352.                     dobj^.do_DefaultTool := olddt;
  353.                     dobj^.do_ToolTypes := oldtt;
  354.                     FreeDiskObject(dobj);
  355.                 End;
  356.             End;            
  357.         End;
  358.     End else begin
  359.         if NOT (destination[length(destination)] = ':') then begin
  360.             if NOT (destination[length(destination)] = '/') then
  361.                 destination := destination + '/';
  362.         End;
  363.         pathvarname := CStrConstPtrAR(@RememberKey, destination+'Path');
  364.         textvarname := CStrConstPtrAR(@RememberKey, destination+'Text');
  365.         penvarname  := CStrConstPtrAR(@RememberKey, destination+'Pens');
  366.         l := CreateDir(drwname);
  367.         UnLock(l);
  368.         flags := GVF_GLOBAL_ONLY;
  369.         OK := SetVar(pathvarname, pathptr, -1, flags);
  370.         OK := SetVar(textvarname, textptr, -1, flags);
  371.         OK := SetVar(penvarname, penptr, -1, flags);
  372.     End;
  373.     FreePath(pathptr);
  374. end;
  375.  
  376. Procedure GetPrefs(dir : String);
  377.  
  378. TYPE
  379.     pBuf = ^tBuf;
  380.     tBuf = packed Array[0..1000] of char;
  381.     
  382. VAR
  383.     flags       : LONG;
  384.     buf         : pBuf;
  385.     len         : Integer;
  386.     ch          : char;
  387.     s           : String;
  388.     n           : Integer;
  389.     inq         : Boolean;
  390.     node        : pNode;
  391.     pathvarname,
  392.     textvarname,
  393.     penvarname  : STRPTR;
  394.     l, f : BPTR;
  395.     fib : pFileInfoBlock;
  396.     
  397. Procedure ParsePath(b : pBuf);
  398.  
  399. Begin
  400.     Begin
  401.         n := 0;
  402.         ch := b^[n];
  403.         s := '';
  404.         inq := False;
  405.         OK := True;
  406.         While OK do begin
  407.             if not (ch in ['"',' ',''#0,''#10]) then begin
  408.                 s := s + ch;
  409.                 inc(n);
  410.                 ch := b^[n];
  411.             end else begin
  412.                 if ch = '"' then begin
  413.                     if inq = True then
  414.                         inq := False
  415.                     else
  416.                         inq := True;
  417.                 end else begin
  418.                     if NOT (ch = ''#0) then begin
  419.                         if  NOT (ch = ''#10) then begin
  420.                             if NOT inq then begin
  421.                                 node := AllocRemember(@RememberKey, Sizeof(tNode), MEMF_CLEAR);
  422.                                 if node <> NIL then begin
  423.                                     node^.ln_Name := CStrConstPtrAR(@RememberKey, s);
  424.                                     AddTail(GD.gd_Path, node);
  425.                                     s := '';
  426.                                 end;
  427.                             end else begin
  428.                                 s:= s + ' ';
  429.                             End;
  430.                         end;
  431.                     end else begin
  432.                         if s <> '' then begin
  433.                             node := AllocRemember(@RememberKey, Sizeof(tNode), MEMF_CLEAR);
  434.                             if node <> NIL then begin
  435.                                 node^.ln_Name := CStrConstPtrAR(@RememberKey, s);
  436.                                 AddTail(GD.gd_Path, node);
  437.                             end;
  438.                         end;
  439.                         OK := False;
  440.                     end;
  441.                 end;
  442.                 inc(n);
  443.                 ch := b^[n];
  444.             end;
  445.         end;    
  446.     end;
  447. End;
  448.  
  449. Procedure ParseText(b : pBuf);
  450.  
  451. Begin
  452.     s := UpperStr(PtrToPas(STRPTR(b)));
  453.     if s[length(s)] = ''#10 then
  454.         s := Copy(s,1,length(s)-1);
  455.     GD.gd_Text := T_BUTTON;
  456.     if s = 'HIGHLIGHT' then
  457.         GD.gd_Text := T_HIGHLIGHT;
  458.     if s = 'UNDERLINE' then
  459.         GD.gd_Text := T_UNDERLINE;
  460.     if s = 'BOLD' then
  461.         GD.gd_Text := T_BOLD;
  462.     if s = 'ITALIC' then
  463.         GD.gd_Text := T_ITALIC; 
  464. end;
  465.  
  466. Procedure ParsePens(b : pBuf);
  467.  
  468. Begin
  469.     s := PtrToPas(STRPTR(b));
  470.     GD.gd_Pens[P_BG] := ord(s[P_BG+1])-48;
  471.     GD.gd_Pens[P_BT] := ord(s[P_BT+1])-48; 
  472.     GD.gd_Pens[P_BBG] := ord(s[P_BBG+1])-48;
  473.     GD.gd_Pens[P_HBT] := ord(s[P_HBT+1])-48;
  474.     GD.gd_Pens[P_HBBG] := ord(s[P_HBBG+1])-48;
  475.     GD.gd_Pens[P_OP] := ord(s[P_OP+1])-48;
  476.     GD.gd_Pens[P_HOP] := ord(s[P_HOP+1])-48;
  477.     GD.gd_Pens[P_TBGP] := ord(s[P_TBGP+1])-48;
  478. end;
  479.  
  480.  
  481. begin
  482.     l := Lock(CStrConstPtrAR(@RememberKey, dir), ACCESS_READ);
  483.     if l <> NULL then begin
  484.         fib := AllocDosObject(DOS_FIB, NIL);
  485.         if fib <> NIL then begin
  486.             If Examine(l, fib) then begin
  487.                 buf := AllocVec(Sizeof(tBuf), MEMF_CLEAR);
  488.                 if buf <> NIL then begin
  489.                     if fib^.fib_DirEntryType > 0 then begin
  490.                         {dir}
  491.                         if NOT (dir[length(dir)] = ':') then begin
  492.                             if NOT (dir[length(dir)] = '/') then
  493.                                 dir := dir + '/';
  494.                         End;
  495.                         pathvarname := CStrConstPtrAR(@RememberKey, dir+'Path');
  496.                         textvarname := CStrConstPtrAR(@RememberKey, dir+'Text');
  497.                         penvarname  := CStrConstPtrAR(@RememberKey, dir+'Pens');
  498.                         flags := GVF_GLOBAL_ONLY;
  499.                         len := GetVar(pathvarname, STRPTR(buf), Sizeof(buf^), flags);
  500.                         if len <> -1 then
  501.                             ParsePath(buf);
  502.                         len := GetVar(textvarname, STRPTR(buf), Sizeof(buf^), flags);
  503.                         if len <> -1 then
  504.                             ParseText(buf);
  505.                         len := GetVar(penvarname, STRPTR(buf), Sizeof(buf^), flags);
  506.                         if len <> -1 then
  507.                             ParsePens(buf);
  508.                         UnLock(l);
  509.                     End;
  510.                     if fib^.fib_DirEntryType < 0 then begin
  511.                         {file}
  512.                         f := OpenFromLock(l);
  513.                         if f <> NULL then begin
  514.                             flags := AmigaDos.Seek_(f,0, OFFSET_BEGINNING);
  515.                             buf := pBuf(FGets(f,STRPTR(buf),Sizeof(tBuf)));
  516.                             if buf <> NIL then
  517.                                 ParsePath(buf);
  518.                             buf := pBuf(FGets(f,STRPTR(buf),Sizeof(tBuf)));
  519.                             if buf <> NIL then
  520.                                 ParseText(buf);
  521.                             buf := pBuf(FGets(f,STRPTR(buf),Sizeof(tBuf)));
  522.                             if buf <> NIL then
  523.                                 ParsePens(buf);
  524.                             Ok := Close_(f);
  525.                         end else
  526.                             UnLock(l);
  527.                     End;
  528.                     FreeVec(buf);
  529.                 End;
  530.             End;
  531.             FreeDosObject(DOS_FIB, fib);
  532.         End;
  533.     End;
  534. end;
  535.  
  536.  
  537. { draw a sample of how the current settings would look }
  538. Procedure DrawSample(rp : pRastPort);
  539.  
  540. Var
  541.     t     : Array[0..6] of LONG;
  542.     it    : pIntuiText;
  543.     dtext : String;
  544.  
  545. Begin
  546.     { fill background colour }
  547.     SetAPen(rp, GD.gd_Pens[P_BG]);
  548.     RectFill(rp, 226, TBS+65, 345, TBS+144);
  549.     
  550.     { fill link point box }
  551.     SetAPen(rp, GD.gd_Pens[P_BBG]);
  552.     RectFill(rp, 245, TBS+75, 326, TBS+84);
  553.     
  554.     { fill selected link point box }
  555.     SetAPen(rp, GD.gd_Pens[P_HBBG]);
  556.     RectFill(rp, 245, TBS+85, 326, TBS+94);
  557.     
  558.     If GD.gd_Text = T_BUTTON then begin
  559.         { draw bevelboxes around the link points }
  560.         t[0] := GT_VisualInfo;
  561.         t[1] := LONG(vi);
  562.         t[2] := GTBB_FrameType;
  563.         t[3] := 0;
  564.         t[4] := TAG_END;
  565.         DrawBevelBoxA(rp, 245, TBS+75, 82, 10, @t);
  566.         t[4] := GTBB_Recessed;
  567.         t[5] := True_;
  568.         t[6] := TAG_END;
  569.         DrawBevelBoxA(rp, 245, TBS+85, 82, 10, @t);
  570.     End;
  571.     
  572.     it := AllocVec(Sizeof(tIntuiText), MEMF_CLEAR);
  573.     if it <> NIL then begin
  574.     
  575.         { set link text style }
  576.         Case GD.gd_Text of
  577.             T_HIGHLIGHT : Topaz8.ta_Style := FSF_EXTENDED;
  578.             T_UNDERLINE : Topaz8.ta_Style := FSF_UNDERLINED;
  579.             T_BOLD      : Topaz8.ta_Style := FSF_BOLD;
  580.             T_ITALIC    : Topaz8.ta_Style := FSF_ITALIC; 
  581.             else Topaz8.ta_Style := 0; 
  582.         End;
  583.         
  584.         { link point text }
  585.         dtext := 'node'#0;
  586.         it^.FrontPen  := GD.gd_Pens[P_BT];
  587.         it^.BackPen := GD.gd_Pens[P_BBG]; 
  588.         it^.LeftEdge := 270;
  589.         it^.TopEdge  := TBS+76;
  590.         it^.ITextFont:= @topaz8;
  591.         it^.IText    := @dtext[1];
  592.         it^.NextText := NIL;
  593.         PrintIText(rp, it, 0, 0);
  594.         
  595.         { selected link point text }
  596.         dtext := 'Selected'#0;
  597.         it^.FrontPen := GD.gd_Pens[P_HBT];
  598.         it^.BackPen  := GD.gd_Pens[P_HBBG]; 
  599.         it^.LeftEdge := 255;
  600.         it^.TopEdge  := TBS+86;
  601.         PrintIText(rp, it, 0, 0);
  602.         
  603.         Topaz8.ta_Style := 0;
  604.         
  605.         { sample text }
  606.         dtext := 'A wee bit of'#0;
  607.         it^.FrontPen := GD.gd_Pens[P_TBGP];
  608.         it^.BackPen  := GD.gd_Pens[P_BG]; 
  609.         it^.LeftEdge := 235;
  610.         it^.TopEdge  := TBS+96;
  611.         PrintIText(rp, it, 0, 0);
  612.         
  613.         dtext := 'text.'#0;
  614.         it^.TopEdge  := TBS+106;
  615.         PrintIText(rp, it, 0, 0);
  616.         
  617.         dtext := 'Wangi!'#0;
  618.         it^.TopEdge  := TBS+126;
  619.         PrintIText(rp, it, 0, 0);
  620.         
  621.         { label above the sample area }
  622.         dtext := 'Sample'#0;
  623.         it^.FrontPen := highlightpen;
  624.         it^.BackPen  := 0; 
  625.         it^.LeftEdge := 262;
  626.         it^.TopEdge  := TBS+53;
  627.         PrintIText(rp, it, 0, 0);
  628.          
  629.         FreeVec(it);
  630.     End;
  631.     
  632.     { bevler around the sample area }
  633.     t[0] := GT_VisualInfo;
  634.     t[1] := LONG(vi);
  635.     t[2] := GTBB_Recessed;
  636.     t[3] := True_;
  637.     t[4] := TAG_END;
  638.     DrawBevelBoxA(rp, 226, TBS+65, 120, 80, @t);
  639. End;
  640.  
  641.  
  642. (*
  643.  * A little routine to fill in the members of a NewMenu struct
  644.  *
  645.  * Cheat & use a bit of assembler to get direct access to the embedded
  646.  * string constants
  647.  *)
  648. procedure nm(var mnm: tNewMenu;
  649.     nmType: byte;
  650.     nmLabel: string;
  651.     nmCommKey: string;
  652.     nmFlags: word;
  653.     nmMutualExclude: longint;
  654.     nmUserData: LONG); assembler;
  655. asm
  656.     move.l    mnm,a0                        { address of the element }
  657.     move.b    nmType,tNewMenu.nm_Type(a0)    { copy the type }
  658.  
  659.     move.l    nmLabel,a1                    { the address of the Pascal string }
  660.     tst.b    (a1)+                        { check for zero length & skip length byte }
  661.     bne        @1                            { if not zero, nothing to do }
  662.     move.l    #NM_BARLABEL,a1                { substitute empty strings with a bar }
  663. @1:    move.l    a1,tNewMenu.nm_Label(a0)    { store the C string }
  664.  
  665.     move.l    nmCommKey,a1                { same for the CommKey }
  666.     tst.b    (a1)+
  667.     bne        @2
  668.     suba.l    a1,a1                        { use nil if the empty string }
  669. @2:    move.l    a1,tNewMenu.nm_CommKey(a0)
  670.  
  671. { the remaining fields }
  672.     move.w    nmFlags,tNewMenu.nm_Flags(a0)
  673.     move.l    nmMutualExclude,tNewMenu.nm_MutualExclude(a0)
  674.     move.l    nmUserData,tNewMenu.nm_UserData(a0)
  675. end;
  676.  
  677.  
  678.  
  679. Function Open_Window : Boolean;
  680.  
  681. Type
  682.     pPenList = ^tPenList;
  683.     tPenList = Array[0..9] of Integer;
  684.     
  685. VAR
  686.     ng               : tNewGadget;
  687.     WindowIDCMP, 
  688.     Depth, ModeID,
  689.     Flg8             : LONG;
  690.     ScreenDef        : pScreen;
  691.     node             : pNode;
  692.     dri              : pDrawInfo;
  693.     Handle           : Pointer;
  694.     pubname          : Boolean;
  695.     mm               : Array[0..26] of tNewMenu;
  696.     di               : pDrawInfo;
  697.  
  698. Begin
  699.     Open_Window := False;    
  700.     
  701.     { set up topaz font for window and gadgets }
  702.     Topaz8.ta_Name  := CStrConstPtrAR(@RememberKey, 'topaz.font');
  703.     Topaz8.ta_YSize := 8;
  704.     Topaz8.ta_Style := 0;
  705.     Topaz8.ta_Flags := 0;
  706.  
  707.     { the IDCMP Classes we want to be told about }
  708.     WindowIDCMP := IDCMP_REFRESHWINDOW|BUTTONIDCMP|LISTVIEWIDCMP|PALETTEIDCMP|IDCMP_MENUPICK|IDCMP_CLOSEWINDOW;
  709.     
  710.     gads[G_NI]  := NIL;
  711.    
  712.   { get details of the screen we are going to open on }
  713.  
  714.     pubname := False;
  715.   if v.arg_PubScreen = '' then
  716.         ScreenDef := LockPubScreen(NIL)
  717.     Else begin    
  718.         pubname := True;
  719.         ScreenDef := LockPubScreen(CStrConstPtrAR(@RememberKey, v.arg_PubScreen));
  720.     end;
  721.     if screendef = NIL then begin
  722.         pubname := False;
  723.         ScreenDef := LockPubScreen(NIL);
  724.     End;
  725.     
  726.     di := GetScreenDrawInfo(ScreenDef);
  727.     if di <> NIL then begin
  728.         highlightpen := pPenList(di^.dri_Pens)^[HIGHLIGHTTEXTPEN];
  729.         FreeScreenDrawInfo(ScreenDef, di);
  730.     End else
  731.         highlightpen := 1;
  732.  
  733.     TBS := screendef^.WBorTop + (screendef^.Font^.ta_YSize + 1);
  734.     
  735.     Depth := -1;
  736.     dri := GetScreenDrawInfo(Screendef);
  737.     if dri <> NIL then
  738.         depth := dri^.dri_Depth;
  739.     FreeScreenDrawInfo(ScreenDef, dri);
  740.     If Depth < 2 then depth := 2;
  741.     if depth > 8 then depth := 8;
  742.     
  743.     if depth >=3 then
  744.         flg8 := 0
  745.     else
  746.         flg8 := NM_ITEMDISABLED;
  747.     
  748.     { init. menu structs. }
  749.     nm(mm[ 0], NM_TITLE, 'Project'#0, '', 0, 0, 0);
  750.     nm(mm[ 1], NM_ITEM , 'Open...'#0, 'O'#0, 0, 0, M_OPEN);
  751.     nm(mm[ 2], NM_ITEM , 'Save As...'#0, 'A'#0, 0, 0, M_SAVAS);
  752.     nm(mm[ 3], NM_ITEM , '', '', 0, 0, 0);
  753.     nm(mm[ 4], NM_ITEM , 'About'#0, '?'#0, 0, 0, M_ABOUT);
  754.     nm(mm[ 5], NM_ITEM , '', '', 0, 0, 0);
  755.     nm(mm[ 6], NM_ITEM , 'Quit'#0, 'Q'#0, 0, 0, M_QUIT);
  756.     
  757.     nm(mm[ 7], NM_TITLE, 'Edit'#0, '', 0, 0, 0);
  758.     nm(mm[ 8], NM_ITEM , 'Reset To Defaults'#0, 'D'#0, 0, 0, M_DEF);
  759.     nm(mm[ 9], NM_ITEM , 'Last Saved'#0, 'L'#0, 0, 0, M_LASTS);
  760.     nm(mm[10], NM_ITEM , 'Restore'#0, 'R'#0, 0, 0, M_REST);
  761.     nm(mm[11], NM_ITEM , 'Presets'#0, '', 0, 0, M_PRE);
  762.     nm(mm[12], NM_SUB  , 'Sharp'#0, '1'#0, 0, 0, M_PRE1);
  763.     nm(mm[13], NM_SUB  , 'Wangi'#0, '2'#0, flg8, 0, M_PRE2);
  764.     nm(mm[14], NM_SUB  , 'Strappado'#0, '3'#0, flg8, 0, M_PRE3);
  765.     nm(mm[15], NM_SUB  , 'Skerza'#0, '4'#0, flg8, 0, M_PRE4);
  766.     nm(mm[16], NM_SUB  , 'Default'#0, '5'#0, 0, 0, M_PRE5);
  767.     nm(mm[17], NM_SUB  , 'Monochrome'#0, '6'#0, 0, 0, M_PRE6);
  768.     nm(mm[18], NM_SUB  , 'Light & Easy'#0, '7'#0, 0, 0, M_PRE7);
  769.     nm(mm[19], NM_SUB  , 'Baked Beans'#0, '8'#0, flg8, 0, M_PRE8);
  770.     nm(mm[20], NM_SUB  , 'Sadad'#0, '9'#0, flg8, 0, M_PRE9);
  771.     nm(mm[21], NM_SUB  , 'heterophyte'#0, '0'#0, flg8, 0, M_PREA);
  772.     nm(mm[22], NM_SUB  , 'Alcohol Results'#0, 'B'#0, flg8, 0, M_PREB);
  773.     nm(mm[23], NM_SUB  , 'MagicWB'#0, 'M'#0, flg8, 0, M_PREM);
  774.     
  775.     nm(mm[24], NM_TITLE, 'Settings'#0, '', 0, 0, 0);
  776.     flg8 := CHECKIT|MENUTOGGLED;
  777.     if v.arg_SIcons then
  778.         flg8 := flg8 | CHECKED;
  779.     nm(mm[25], NM_ITEM , 'Create Icons?'#0, 'I'#0, flg8, 0, M_ICON);
  780.     nm(mm[26], NM_END  , ''#0, '', 0, 0, 0);
  781.     
  782.     ZoomS[0] := -1;
  783.     ZoomS[1] := -1;
  784.     ZoomS[2] := 200;
  785.     ZoomS[3] := TBS;
  786.  
  787.     { Get visual info and create context }
  788.     vi := GetVisualInfoA(screendef, NIL);
  789.     If vi <> NIL Then begin
  790.         Gads[G_CC] := CreateContext(@gads[G_NI]);
  791.         If Gads[G_CC] <> NIL Then begin
  792.  
  793.             { mak' the gads. }
  794.             With ng do begin
  795.                 ng_LeftEdge := 16;
  796.                 ng_TopEdge := 0;
  797.                 ng_Width := 202;
  798.                 ng_Height := 14;
  799.                 ng_GadgetText := NIL;
  800.                 ng_TextAttr := @Topaz8;
  801.                 ng_GadgetID := G_PATHT;
  802.                 ng_Flags := 0;
  803.                 ng_VisualInfo := vi;
  804.                 ng_UserData := NIL;
  805.             end;
  806.             Gads[G_PATHT] := CreateGadgetA(STRING_KIND, gads[G_CC], @ng, NIL);
  807.             
  808.             With ng do begin
  809.                 ng_TopEdge := TBS+18;
  810.                 ng_Height := 100;
  811.                 ng_GadgetText := CStrConstPtrAR(@RememberKey, 'Paths');
  812.                 ng_GadgetID := G_PATH;
  813.                 ng_Flags := PLACETEXT_ABOVE|NG_HIGHLABEL;
  814.             end;
  815.             t[0] := GTLV_Labels;
  816.             t[1] := LONG(GD.gd_Path);
  817.             t[2] := GTLV_ShowSelected;
  818.             t[3] := LONG(Gads[G_PATHT]);
  819.             t[4] := GTLV_Selected;
  820.             t[5] := -1;
  821.             t[6] := TAG_END;
  822.             Gads[G_PATH] := CreateGadgetA(LISTVIEW_KIND, gads[G_PATHT], @ng, @t);
  823.             
  824.             With ng do begin
  825.                 ng_TopEdge := Gads[G_PATHT]^.TopEdge+Gads[G_PATHT]^.Height+4;
  826.                 ng_Height := 14;
  827.                 ng_GadgetText := CStrConstPtrAR(@RememberKey, 'Directory...');
  828.                 ng_GadgetID := G_FR;
  829.                 ng_Flags := PLACETEXT_IN;
  830.             end;
  831.             Gads[G_FR] := CreateGadgetA(BUTTON_KIND, gads[G_PATH], @ng, NIL);
  832.             
  833.             With ng do begin
  834.                 ng_TopEdge := ng_TopEdge+ng_Height;
  835.                 ng_GadgetText := CStrConstPtrAR(@RememberKey, 'New');
  836.                 ng_GadgetID := G_NEW;
  837.                 ng_Width := 100;
  838.             end;
  839.             Gads[G_NEW] := CreateGadgetA(BUTTON_KIND, gads[G_FR], @ng, NIL);
  840.             
  841.             With ng do begin
  842.                 ng_GadgetText := CStrConstPtrAR(@RememberKey, 'Remove');
  843.                 ng_GadgetID := G_REM;
  844.                 ng_LeftEdge := ng_LeftEdge+100+2;
  845.             end;
  846.             Gads[G_REM] := CreateGadgetA(BUTTON_KIND, gads[G_NEW], @ng, NIL);
  847.             
  848.             TextLabs[T_BUTTON]    := CStrConstPtrAR(@RememberKey, 'Button');
  849.             TextLabs[T_HIGHLIGHT] := CStrConstPtrAR(@RememberKey, 'Highlight');
  850.             TextLabs[T_UNDERLINE] := CStrConstPtrAR(@RememberKey, 'Underline');
  851.             TextLabs[T_BOLD]      := CStrConstPtrAR(@RememberKey, 'Bold');
  852.             TextLabs[T_ITALIC]    := CStrConstPtrAR(@RememberKey, 'Italic');
  853.             TextLabs[T_NULL]      := NIL;
  854.             
  855.             t[0] := GTCY_Labels;
  856.             t[1] := LONG(@TextLabs);
  857.             t[2] := GTCY_Active;
  858.             t[3] := GD.gd_Text;
  859.             t[4] := TAG_END;
  860.             With ng do begin
  861.                 ng_LeftEdge := ng_LeftEdge+ng_Width+8;
  862.                 ng_TopEdge := TBS+18;
  863.                 ng_Height := 14;
  864.                 ng_Width := 120;
  865.                 ng_GadgetText := CStrConstPtrAR(@RememberKey, 'Text');
  866.                 ng_GadgetID := G_TEXT;
  867.                 ng_Flags := PLACETEXT_ABOVE|NG_HIGHLABEL;
  868.             end;
  869.             Gads[G_TEXT] := CreateGadgetA(CYCLE_KIND, gads[G_REM], @ng, @t);
  870.             
  871.             PenLabs[P_BG]   := CStrConstPtrAR(@RememberKey, 'Background');
  872.             PenLabs[P_BT]   := CStrConstPtrAR(@RememberKey, 'Button text');
  873.             PenLabs[P_BBG]  := CStrConstPtrAR(@RememberKey, 'Button Background');
  874.             PenLabs[P_HBT]  := CStrConstPtrAR(@RememberKey, 'Highlighted button text');
  875.             PenLabs[P_HBBG] := CStrConstPtrAR(@RememberKey, 'Highlighted button backround');
  876.             PenLabs[P_OP]   := CStrConstPtrAR(@RememberKey, 'Outline pen');
  877.             PenLabs[P_HOP]  := CStrConstPtrAR(@RememberKey, 'Highlighted outline pen');
  878.             PenLabs[P_TBGP] := CStrConstPtrAR(@RememberKey, 'Text on Background pen');
  879.              
  880.             PenList := AllocRemember(@RememberKey, Sizeof(tList), MEMF_CLEAR);
  881.             NewList(PenList);
  882.             For n := P_BG to P_TBGP do begin
  883.                 node := AllocRemember(@RememberKey, Sizeof(tNode), MEMF_CLEAR);
  884.                 if Node <> NIL then begin
  885.                     node^.ln_Name := PenLabs[n];
  886.                     AddTail(PenList, node);
  887.                 end;
  888.             end;
  889.  
  890.             t[0] := GTLV_Labels;
  891.             t[1] := LONG(PenList);
  892.             t[2] := GTLV_ShowSelected;
  893.             t[3] := 0;
  894.             t[4] := GTLV_Selected;
  895.             t[5] := 0;
  896.             t[6] := TAG_END;
  897.             With ng do begin
  898.                 ng_LeftEdge := ng_LeftEdge+ng_Width+8;
  899.                 ng_TopEdge := TBS+18;
  900.                 ng_Height := 70;
  901.                 ng_Width := 250;
  902.                 ng_GadgetText := CStrConstPtrAR(@RememberKey, 'Pens');
  903.                 ng_GadgetID := G_PENS;
  904.                 ng_Flags := PLACETEXT_ABOVE|NG_HIGHLABEL;
  905.             end;
  906.             Gads[G_PENS] := CreateGadgetA(LISTVIEW_KIND, gads[G_TEXT], @ng, @t);
  907.             
  908.             t[0] := GTPA_Depth;
  909.             t[1] := Depth;
  910.             t[2] := GTPA_Color;
  911.             t[3] := GD.gd_Pens[0];
  912.             t[4] := GTPA_IndicatorWidth;
  913.             t[5] := 20;
  914.             t[6] := GTPA_NumColors;
  915.             if depth >= 8 then
  916.                 t[7] := MAX_COLOURS
  917.             else
  918.                 t[7] := 1 shl depth; 
  919.             t[8] := TAG_END;
  920.             With ng do begin
  921.                 ng_TopEdge := Gads[G_PENS]^.TopEdge+Gads[G_PENS]^.Height+1;
  922.                 if GadToolsBase^.lib_Version < 38 then
  923.                     ng_TopEdge := ng_TopEdge + 12;
  924.                 ng_Height := (Gads[G_REM]^.TopEdge+Gads[G_REM]^.Height)-(Gads[G_PENS]^.TopEdge+Gads[G_PENS]^.Height);
  925.                 if GadToolsBase^.lib_Version < 38 then
  926.                     ng_Height := ng_Height - 12;
  927.                 ng_Width := 250;
  928.                 ng_GadgetText := NIL;
  929.                 ng_GadgetID := G_PENP;
  930.                 ng_Flags := 0;
  931.             end;
  932.             Gads[G_PENP] := CreateGadgetA(PALETTE_KIND, gads[G_PENS], @ng, @t);
  933.             
  934.             With ng do begin
  935.                 ng_LeftEdge := 16;
  936.                 ng_Width := 86;
  937.                 ng_Height := 14;
  938.                 ng_TopEdge := gads[G_REM]^.TopEdge+gads[G_REM]^.Height+8;
  939.                 ng_GadgetText := CStrConstPtrAR(@RememberKey, 'Save');
  940.                 ng_GadgetID := G_SAVE;
  941.             end;
  942.             Gads[G_SAVE] := CreateGadgetA(BUTTON_KIND, gads[G_PENP], @ng, NIL);
  943.             
  944.             With ng do begin
  945.                 ng_LeftEdge := gads[G_PENS]^.LeftEdge+gads[G_PENS]^.Width-ng_Width;
  946.                 ng_GadgetText := CStrConstPtrAR(@RememberKey, 'Cancel');
  947.                 ng_GadgetID := G_CAN;
  948.             end;
  949.             Gads[G_CAN] := CreateGadgetA(BUTTON_KIND, gads[G_SAVE], @ng, NIL);
  950.             
  951.             With ng do begin
  952.                 ng_LeftEdge := (ng_LeftEdge div 2) {- (ng_Width div 2)};
  953.                 ng_GadgetText := CStrConstPtrAR(@RememberKey, 'Use');
  954.                 ng_GadgetID := G_USE;
  955.             end;
  956.             Gads[G_USE] := CreateGadgetA(BUTTON_KIND, gads[G_CAN], @ng, NIL);
  957.  
  958.             
  959.             t[0]  := WA_Flags;
  960.             t[1]  := WFLG_ACTIVATE|WFLG_DRAGBAR|WFLG_DEPTHGADGET|WFLG_SIMPLE_REFRESH|WFLG_NEWLOOKMENUS;
  961.             t[2]  := WA_Title;
  962.             t[3]  := LONG(CStrConstPtrAR(@RememberKey, 'AmigaGuide Preferences'));
  963.             t[4]  := WA_Gadgets;
  964.             t[5]  := Long(Gads[G_NI]);
  965.             t[6]  := WA_IDCMP;
  966.             t[7]  := WindowIDCMP;
  967.             t[8]  := WA_Left;
  968.             t[9]  := 0;
  969.             t[10] := WA_Top;
  970.             t[11] := TBS;
  971.             t[12] := WA_Width;
  972.             t[13] := gads[G_CAN]^.Width+gads[G_CAN]^.LeftEdge+16;
  973.             t[14] := WA_Height;
  974.             t[15] := ng.ng_Height+ng.ng_TopEdge+8;
  975.             t[16] := WA_Zoom;
  976.             t[17] := LONG(@ZoomS);
  977.             if v.arg_PubScreen <> '' then begin
  978.                 t[18] := WA_PubScreenName;
  979.                 t[19] := LONG(CStrConstPtrAR(@RememberKey, v.arg_PubScreen));
  980.                 t[20] := WA_PubScreenFallBack;
  981.                 t[21] := True_;
  982.                 t[22] := TAG_END;
  983.             End else
  984.                 t[18] := TAG_END;
  985.             
  986.             TheWindow := OpenWindowTagList(NIL, @t);
  987.             if TheWindow <> NIL then begin
  988.             
  989.                 t[0] := GTMN_NewLookMenus;
  990.                 t[1] := True_;
  991.                 t[2] := TAG_END;
  992.                 menustrip := CreateMenusA(@mm, NIL);
  993.                 if menustrip <> NIL then
  994.                     if LayoutMenusA(menustrip,vi,@t) then
  995.                         OK := SetMenuStrip(TheWindow,MenuStrip);
  996.  
  997.                 DrawSample(TheWindow^.RPort);
  998.                 GT_RefreshWindow(TheWindow, NIL);
  999.                 Open_Window := True;
  1000.             end;
  1001.         end;
  1002.     end;
  1003.     UnLockPubScreen(NIL, Screendef);
  1004. end;
  1005.  
  1006. Procedure Close_Window;
  1007.  
  1008. Begin
  1009.     if MenuStrip <> NIL then begin
  1010.         ClearMenuStrip(TheWindow);
  1011.         FreeMenus(MenuStrip);
  1012.     end;
  1013.     CloseWindow(TheWindow);
  1014.     FreeGadgets(gads[G_NI]);
  1015.     FreeVisualInfo(vi);
  1016. End;
  1017.  
  1018. Procedure DetachPathList;
  1019.  
  1020. VAR 
  1021.     Tag_Array : array[0..2] of LONG;
  1022.  
  1023. begin
  1024.     Tag_Array[0] := GTLV_Labels;
  1025.     Tag_Array[1] := $FFFFFFFF;
  1026.     Tag_Array[2] := TAG_END;
  1027.     GT_SetGadgetAttrsA(gads[G_PATH], TheWindow, NIL, @Tag_Array);
  1028. end;
  1029.  
  1030. Procedure AttachPathList;
  1031.  
  1032. VAR 
  1033.     Tag_Array : array[0..4] of LONG;
  1034.  
  1035. begin
  1036.     Tag_Array[0] := GTLV_Labels;
  1037.     Tag_Array[1] := LONG(GD.gd_Path);
  1038.     Tag_Array[2] := GTLV_Selected; 
  1039.     Tag_Array[3] := CurpathOrd;
  1040.     Tag_Array[4] := TAG_END;
  1041.     GT_SetGadgetAttrsA(gads[G_PATH], TheWindow, NIL, @Tag_Array);
  1042. end;
  1043.  
  1044. Procedure RemakeWindow;
  1045.  
  1046. begin
  1047.     t[0] := GTCY_Active;
  1048.     t[1] := GD.gd_Text;
  1049.     t[2] := TAG_END;
  1050.     GT_SetGadgetAttrsA(gads[G_TEXT], TheWindow, NIL, @t);
  1051.     
  1052.     t[0] := GTPA_Color;
  1053.     t[1] := GD.gd_Pens[curpen];
  1054.     t[2] := TAG_END;
  1055.     GT_SetGadgetAttrsA(gads[G_PENP], TheWindow, NIL, @t);
  1056. end;
  1057.  
  1058.  
  1059. Procedure HandleWindow;
  1060.  
  1061. CONST
  1062.     Exitflag : Boolean = False;
  1063.     
  1064. VAR 
  1065.     dummy      : LONG;
  1066.     message    : pIntuiMessage;
  1067.     MsgClass   : LONG;
  1068.     MsgCode, y : Word;
  1069.     Gadcode    : pGadget;
  1070.     StrInfo    : pStringInfo;
  1071.     menunumber : Word;
  1072.     item       : pMenuItem;
  1073.     curpathnode, 
  1074.     node       : pNode;
  1075.     RK         : pRemember;
  1076.     ez         : pEasyStruct;
  1077.     s, s2      : String;
  1078.     tga        : STRPTR;
  1079.     updatesamp : Boolean;
  1080.  
  1081. Procedure SetPresets(pres : tPreset);
  1082.  
  1083. Begin
  1084.     GD.gd_Pens[P_BG]   := pres[1];
  1085.     GD.gd_Pens[P_BT]   := pres[2];
  1086.     GD.gd_Pens[P_BBG]  := pres[3];
  1087.     GD.gd_Pens[P_HBT]  := pres[4];
  1088.     GD.gd_Pens[P_HBBG] := pres[5];
  1089.     GD.gd_Pens[P_OP]   := pres[6];
  1090.     GD.gd_Pens[P_HOP]  := pres[7];
  1091.     GD.gd_Pens[P_TBGP] := pres[8];
  1092.     GD.gd_Text         := pres[9];
  1093.     RemakeWindow;
  1094.     updatesamp := True;
  1095. End;
  1096.  
  1097.  
  1098.  
  1099. begin
  1100.     s2 := 'SYS:Prefs/Presets/AmigaGuide';
  1101.     curpathnode := NIL;
  1102.     While Not exitflag Do Begin
  1103.         dummy    := Wait(BitMask(TheWindow^.UserPort^.MP_SIGBIT));
  1104.         message  := GT_GetIMsg(TheWindow^.userPort);
  1105.         while message <> NIL do begin
  1106.             updatesamp := False;
  1107.             MsgClass := message^.Class;
  1108.             MsgCode  := message^.Code;
  1109.             GadCode  := pGadget(message^.IAddress);            
  1110.             GT_ReplyIMsg(message);
  1111.             Case MsgClass Of
  1112.         
  1113.                 IDCMP_CLOSEWINDOW : ExitFlag := True;
  1114.                 
  1115.                 IDCMP_REFRESHWINDOW : begin
  1116.                     GT_BeginRefresh(TheWindow);
  1117.                     DrawSample(TheWindow^.RPort);
  1118.                     GT_EndRefresh(TheWindow, True);
  1119.                 end;
  1120.                 
  1121.                 IDCMP_MENUPICK : Begin
  1122.                     MenuNumber := MsgCode;
  1123.                     While (menunumber <> MENUNULL) and (ExitFlag = False) do begin
  1124.                         item := ItemAddress(menustrip, menunumber);
  1125.                         CASE LONG(GTMENUITEM_USERDATA(item)) of
  1126.                             M_OPEN : Begin
  1127.                                 s := GetDir(s2, False, False);
  1128.                                 if s <> '' then begin
  1129.                                     DetachPathList;
  1130.                                     SetDefault;
  1131.                                     GetPrefs(s);
  1132.                                     RemakeWindow;
  1133.                                     updatesamp := True;
  1134.                                     CurPathNode := NIL;
  1135.                                     CurPathOrd := -1;
  1136.                                     AttachPathList;
  1137.                                 End;
  1138.                             End;
  1139.                             M_SAVAS : Begin
  1140.                                 s := GetDir(s2, False, True);
  1141.                                 if s <> '' then begin
  1142.                                     s2 := s;
  1143.                                     SetPrefs(s, TRUE);
  1144.                                 End;
  1145.                             End;
  1146.                             M_ABOUT : Begin
  1147.                                 RK := NIL;
  1148.                                 ez := AllocRemember(@RK, Sizeof(tEasyStruct), MEMF_CLEAR);
  1149.                                 if ez <> NIL then begin
  1150.                                     With ez^ do begin
  1151.                                         es_StructSize :=  Sizeof(tEasyStruct);
  1152.                                         es_Title := NIL;
  1153.                                         es_TextFormat := 
  1154.                                             CStrConstPtrAR(@RK, 'Amigaguide Preferences Copyright ©Lee Kindness.'#10+
  1155.                                                                 '%s'#10+
  1156.                                                                 ''#10+
  1157.                                                             'Preference editor for the Amigaguide hypertext system.'#10+
  1158.                                                             'See "AGPrefs.doc" for more information.'#10+
  1159.                                                             ''#10+
  1160.                                                             'Comments to:'#10+
  1161.                                                             ' Lee Kindness'#10+
  1162.                                                             ' 8 Craigmarn Road'#10+
  1163.                                                             ' Portlethen Village'#10+
  1164.                                                             ' Aberdeen AB1 4QR'#10+
  1165.                                                             ' SCOTLAND');
  1166.                                         es_GadgetFormat := CStrConstPtrAR(@RK, 'Ok');
  1167.                                         tga := @Version[7];
  1168.                                         n := EasyRequestArgs(TheWindow, ez, NIL, @tga);
  1169.                                     End;
  1170.                                 End;
  1171.                                 FreeRemember(@RK, True);
  1172.                             end;
  1173.                             M_QUIT : ExitFlag := True;
  1174.                                     
  1175.                             M_DEF : Begin
  1176.                                 DetachPathList;
  1177.                                 SetDefault;
  1178.                                 RemakeWindow;
  1179.                                 updatesamp := True;
  1180.                                 CurPathNode := NIL;
  1181.                                 CurPathOrd := -1;
  1182.                                 AttachPathList;
  1183.                             end;
  1184.                             M_LASTS : Begin
  1185.                                 DetachPathList;
  1186.                                 SetDefault;
  1187.                                 GetPrefs('ENVARC:AmigaGuide/');
  1188.                                 RemakeWindow;
  1189.                                 updatesamp := True;
  1190.                                 CurPathNode := NIL;
  1191.                                 CurPathOrd := -1;
  1192.                                 AttachPathList;
  1193.                             end;
  1194.                             M_REST : Begin
  1195.                                 DetachPathList;
  1196.                                 SetDefault;
  1197.                                 GetPrefs(v.arg_From);
  1198.                                 RemakeWindow;
  1199.                                 updatesamp := True;
  1200.                                 CurPathNode := NIL;
  1201.                                 CurPathOrd := -1;
  1202.                                 AttachPathList;
  1203.                             End;
  1204.                             M_PRE1..M_PREMAX : SetPresets(presets[LONG(GTMENUITEM_USERDATA(item))-8]);
  1205.                             M_ICON : Begin
  1206.                                 if (item^.Flags and CHECKED) <> 0 then
  1207.                                     v.arg_SIcons := True
  1208.                                 else
  1209.                                     v.arg_SIcons:= False;
  1210.                             End;
  1211.                         end;
  1212.                         menunumber := item^.NextSelect;
  1213.                     end;
  1214.                 end;       
  1215.                 
  1216.                 IDCMP_GADGETUP : Begin  
  1217.                     StrInfo  := gadcode^.SpecialInfo;     
  1218.                     Case gadcode^.GadgetID Of 
  1219.                         G_SAVE : begin
  1220.                             ExitFlag := True;
  1221.                             SetPrefs('ENVARC:AmigaGuide/',FALSE);
  1222.                             SetPrefs('ENV:AmigaGuide/',FALSE);
  1223.                         end;
  1224.                         G_USE : begin
  1225.                             ExitFlag := True;
  1226.                             SetPrefs('ENV:AmigaGuide/',FALSE);
  1227.                         end;
  1228.                         G_CAN : ExitFlag := True;
  1229.                         G_PENS : begin
  1230.                             t[0] := GTPA_Color;
  1231.                             t[1] := GD.gd_Pens[msgcode];
  1232.                             t[2] := TAG_END;
  1233.                             GT_SetGadgetAttrsA(Gads[G_PENP], TheWindow, NIL, @t);
  1234.                             curpen := msgcode;
  1235.                         end;
  1236.                         G_PENP : begin
  1237.                             if msgcode > MAX_COLOURS then begin
  1238.                                 DisplayBeep(NIL);
  1239.                                 t[0] := GTPA_Color;
  1240.                                 t[1] := GD.gd_Pens[curpen];
  1241.                                 t[2] := TAG_END;
  1242.                                 GT_SetGadgetAttrsA(gads[G_PENP], TheWindow, NIL, @t);
  1243.                             End else
  1244.                                 GD.gd_Pens[curpen] := msgcode;
  1245.                             updatesamp := True;
  1246.                         End;
  1247.                         G_TEXT : begin
  1248.                             GD.gd_Text := msgcode;
  1249.                             updatesamp := True;
  1250.                         End;
  1251.                         G_PATH : Begin
  1252.                             curpathord := msgcode;
  1253.                             CurpathNode := GD.gd_Path^.lh_Head;
  1254.                             For y := 1 to curpathord do
  1255.                                 CurpathNode := CurpathNode^.ln_Succ;
  1256.                         end;
  1257.                         G_REM : if curpathnode <> NIL then begin
  1258.                             DetachPathList;
  1259.                             Remove(curpathnode);
  1260.                             curpathnode := NIL;
  1261.                             curpathord := -1; 
  1262.                             AttachPathList;
  1263.                         end;
  1264.                         G_NEW : Begin
  1265.                             curpathnode := AllocRemember(@RememberKey, Sizeof(tNode), MEMF_CLEAR);
  1266.                             if curpathnode <> NIL then begin
  1267.                                 curpathnode^.ln_Name := CStrConstPtrAR(@RememberKey, 'SYS:');
  1268.                                 DetachPathList;
  1269.                                 AddTail(GD.gd_Path, curpathnode);
  1270.                                 node := GD.gd_Path^.lh_Head;
  1271.                                 curpathord := 0;
  1272.                                 While node <> curpathnode do begin
  1273.                                     node := node^.ln_Succ;
  1274.                                     Inc(curpathord);
  1275.                                 end;
  1276.                                 AttachPathList;
  1277.                             end;
  1278.                         end;
  1279.                         G_FR : if curpathnode <> NIL then Begin
  1280.                             s := GetDir(PtrToPas(curpathnode^.ln_Name),True,False);
  1281.                             if s <> '' then begin
  1282.                                 DetachPathList;
  1283.                                 curpathnode^.ln_Name := CStrConstPtrAR(@RememberKey, s);
  1284.                                 AttachPathList;
  1285.                             end;
  1286.                         end;
  1287.                         G_PATHT : if curpathnode <> NIL then begin
  1288.                             DetachPathList;
  1289.                             curpathnode^.ln_Name := CStrConstPtrAR(@RememberKey, PtrToPas(STRPTR(StrInfo^.Buffer)));
  1290.                             AttachPathList;
  1291.                         end;
  1292.                     End; {case}
  1293.                 end;
  1294.             End; {case}
  1295.             if updatesamp then
  1296.                 DrawSample(TheWindow^.RPort);
  1297.                 
  1298.             message  := GT_GetIMsg(TheWindow^.userPort);
  1299.         end;
  1300.     End; {while}
  1301. end;
  1302.  
  1303. Begin
  1304.     RememberKey := NIL;
  1305.     IntuitionBase := pIntuitionBase(OpenLibrary('intuition.library',36));
  1306.     GadToolsBase := OpenLibrary('gadtools.library',36);
  1307.     AslBase := OpenLibrary('asl.library', 0);
  1308.     IconBase := OpenLibrary('icon.library', 0);
  1309.     GfxBase := pGfxBase(OpenLibrary('graphics.library',0));
  1310.     
  1311.     if (IntuitionBase <> NIL) and (IconBase <> NIL) and 
  1312.        (GadtoolsBase <> NIL) and (AslBase <> NIL) and (GfxBase <> NIL) then begin
  1313.         GD.gd_Path := AllocRemember(@RememberKey, Sizeof(tList), MEMF_CLEAR);
  1314.         if GD.gd_Path <> NIL then begin
  1315.             GetToolTypes(v);
  1316.             SetDefault;
  1317.             GetPrefs(v.arg_From);
  1318.             if v.arg_Use then
  1319.                 SetPrefs('ENV:AmigaGuide/',FALSE);
  1320.             if v.arg_Save then
  1321.                 SetPrefs('ENVARC:AmigaGuide/',FALSE);
  1322.             if (v.arg_Edit = True) then begin
  1323.                 if Open_Window then begin
  1324.                     HandleWindow;
  1325.                     Close_Window;
  1326.                 end;
  1327.             End;
  1328.         end;
  1329.     
  1330.         FreeRemember(@RememberKey, True);
  1331.         
  1332.         CloseLibrary(pLibrary(GfxBase));
  1333.         CloseLibrary(IconBase);
  1334.         CloseLibrary(AslBase);
  1335.         CloseLibrary(GadToolsBase);
  1336.         CloseLibrary(pLibrary(IntuitionBase));
  1337.     end;
  1338. end.
  1339.